www.gusucode.com > VC++网络版的打字软件源程序-源码程序 > VC++网络版的打字软件源程序-源码程序\code\TypeClt V2.0\KeyWordView.cpp
//Download by http://www.NewXing.com // KeyWordView.cpp : implementation file // #include "stdafx.h" #include "type.h" #include "TypeDoc.h" #include "KeyWordView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CKeyWordView IMPLEMENT_DYNCREATE(CKeyWordView, CTypeOperatorView) CKeyWordView::CKeyWordView() { m_pKeyboard=NULL; for(int nIndex=0;nIndex<NUMBER_EN;nIndex++) { m_ArrEnglishChar[nIndex]='a'+nIndex; m_ArrRightNumber[nIndex]=0; m_ArrWrongNumber[nIndex]=0; } } CKeyWordView::~CKeyWordView() { if(m_pKeyboard!=NULL) { delete m_pKeyboard; m_pKeyboard=NULL; } } BEGIN_MESSAGE_MAP(CKeyWordView, CTypeOperatorView) //{{AFX_MSG_MAP(CKeyWordView) ON_WM_CHAR() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CKeyWordView drawing void CKeyWordView::OnDraw(CDC* pDC) { CTypeDoc* pDoc = (CTypeDoc*)GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here CRect rect; GetClientRect(rect); m_rcType=rect; m_rcType.DeflateRect(0,0,0,rect.Height()/2); m_rcKeyboard=rect; m_rcKeyboard.DeflateRect(0,rect.Height()/2,0,0); ///////////////////////////////////////////////// SetRect(m_rcType); DrawPage(pDC,GetCurPage()); ///////////////////////////////////////////////// if(m_pKeyboard!=NULL) { m_pKeyboard->DrawKeyboard(pDC,m_rcKeyboard); } else { DrawScoreTable(pDC,m_rcKeyboard); } } ///////////////////////////////////////////////////////////////////////////// // CKeyWordView diagnostics #ifdef _DEBUG void CKeyWordView::AssertValid() const { CView::AssertValid(); } void CKeyWordView::Dump(CDumpContext& dc) const { CView::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CKeyWordView message handlers void CKeyWordView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default CTypeOperatorView::OnChar(nChar, nRepCnt, nFlags); if(m_pKeyboard!=NULL) { CDC* pDC=GetDC(); CRect rc=m_rcKeyboard; GetCurChar(m_pKeyboard->m_cChar); m_pKeyboard->DrawKeyboard(pDC,rc); ReleaseDC(pDC); } } void CKeyWordView::OnInitialUpdate() { CTypeOperatorView::OnInitialUpdate(); // TODO: Add your specialized code here and/or call the base class SetPageCols(25); SetPageRows(4); CTypeDoc* pDoc=(CTypeDoc*)GetDocument(); LoadQuestion( pDoc->GetQuestion(), pDoc->GetQuestionInfo(), pDoc->GetTestTime(), pDoc->GetInputLanguage()); if(m_pKeyboard==NULL) { m_pKeyboard=new CKeyboard; } GetCurChar(m_pKeyboard->m_cChar); Invalidate(); } void CKeyWordView::StopTest() { CTypeOperatorView::StopTest(); ///////////////////////////////////////////////////// CountEnglishChar(m_ArrRightNumber,m_ArrWrongNumber); if(m_pKeyboard!=NULL) { delete m_pKeyboard; m_pKeyboard=NULL; } Invalidate(); } void CKeyWordView::DrawScoreTable(CDC *pDC, CRect &rc) { CRect rcTable=rc; int xOffset=rcTable.Width()%14; int yOffset=rcTable.Height()%6; rcTable.DeflateRect(xOffset/2,yOffset/2,xOffset/2,yOffset/2); int nRowHeight=(int)rcTable.Height()/6; int nColWidth=(int)rcTable.Width()/14; int nRow; int nCol; pDC->FillSolidRect(rc,m_clfFill); CPen *pNewPen=new CPen; pNewPen->CreatePen(PS_SOLID,1,m_clfLine); CPen* pOldPen=pDC->SelectObject(pNewPen); pDC->Rectangle(rcTable); for(nRow=1;nRow<6;nRow++) { pDC->MoveTo(rcTable.left+1,rcTable.top+nRow*nRowHeight); pDC->LineTo(rcTable.right-1,rcTable.top+nRow*nRowHeight); } for(nCol=1;nCol<14;nCol++) { pDC->MoveTo(rcTable.left+nCol*nColWidth,rcTable.top+1); pDC->LineTo(rcTable.left+nCol*nColWidth,rcTable.bottom-1); } pDC->SelectObject(pOldPen); delete pNewPen; pNewPen=NULL; CRect rcRow; CRect rcGride; CRect rcChar; CRect rcRight; CRect rcWrong; CString strChar; CString strRight; CString strWrong; int nIndex; for(nRow=0;nRow<2;nRow++) { rcRow.SetRect(rcTable.left,rcTable.top+3*nRow*nRowHeight, rcTable.right,rcTable.top+3*nRow*nRowHeight+nRowHeight); for(nCol=0;nCol<14;nCol++) { rcGride.SetRect(rcRow.left+nCol*nColWidth,rcRow.top, rcRow.left+nCol*nColWidth+nColWidth,rcRow.bottom); rcChar=rcGride; rcGride.OffsetRect(0,nRowHeight); rcRight=rcGride; rcGride.OffsetRect(0,nRowHeight); rcWrong=rcGride; if(nCol==0) { strChar="字母"; strRight="正确"; strWrong="错误"; } else { nIndex=nRow*13+nCol-1; strChar.Format("%c(%c)", m_ArrEnglishChar[nIndex]-('a'-'A'), m_ArrEnglishChar[nIndex]); strRight.Format("%d个",m_ArrRightNumber[nIndex]); strWrong.Format("%d个",m_ArrWrongNumber[nIndex]); } int nMode=pDC->SetBkMode(TRANSPARENT); rcChar.DeflateRect(1,1); pDC->FillSolidRect(rcChar,m_clfFill); pDC->DrawText(strChar,rcChar,DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->DrawText(strRight,rcRight,DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->DrawText(strWrong,rcWrong,DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->SetBkMode(nMode); } } }